package com.onlyphoto.onlymall.mvp.model

import com.onlyphoto.onlymall.api.Urls
import com.onlyphoto.onlymall.base.BaseEntity
import com.onlyphoto.onlymall.base.BaseModel
import com.onlyphoto.onlymall.base.BaseObserver
import com.onlyphoto.onlymall.bean.request.AddressAddBean
import com.onlyphoto.onlymall.bean.request.DeleteAddressBean
import com.onlyphoto.onlymall.bean.response.RegionBean2
import com.onlyphoto.onlymall.utils.ConfigUtil
import com.onlyphoto.onlymall.utils.RxTransformer


class MEditAddressImpl : BaseModel() {
    var url = ""

    fun requestRegion(layout: Int, baseObserver: BaseObserver<RegionBean2>) {
        url = ConfigUtil.instance.getUrl(Urls.REGION)
        apiService().region(url, layout)
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }

    fun addRegion(bean: AddressAddBean, baseObserver: BaseObserver<BaseEntity>) {
        url = ConfigUtil.instance.getUrl(Urls.USER_ADDRESS)
        apiService().addAddress(url, bean.toMap())
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }

    fun updateAddress(bean: AddressAddBean, baseObserver: BaseObserver<BaseEntity>) {
        url = ConfigUtil.instance.getUrl(Urls.USER_ADDRESS)
        apiService().updateAddress(url, bean)
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }

    fun deleteAddress(bean: DeleteAddressBean, baseObserver: BaseObserver<BaseEntity>) {
        url = ConfigUtil.instance.getUrl(Urls.USER_ADDRESS)
        apiService().deleteAddress(url, bean)
                .compose(RxTransformer.switchSchedulers(this))
                .subscribe(baseObserver)
    }
}
